<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false"
    :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()"
      label-width="120px">

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="邀请好友手机号">
        {{ dataForm.mobile }}
      </el-form-item>
        </el-col>

        <el-col :span="12">
    
          <el-form-item label="邀请好姓名">
        {{ dataForm.realName }}
      </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="发起邀请人">
        {{ dataForm.realName || dataForm.inviteUserName }}
      </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="发起邀请手机">
        {{ dataForm.inviteUserPhone }}
      </el-form-item>
        </el-col>
        <el-col :span="12">
 
          <el-form-item label="邀请时间">
        {{ dataForm.inviteTime }}
      </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="红包金额" prop="balance">
        <el-input v-model="dataForm.balance" placeholder="邀请成功获得金额"></el-input>
      </el-form-item>
        </el-col> -->
        <el-col :span="12">
          <el-form-item label="是否注册" prop="isRegist">
        {{ dataForm.isRegist ? '是' : '否' }}
      </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="审核" prop="isPass">
        <el-radio-group v-model="dataForm.isPass">
          <el-radio :label="2">通过</el-radio>
          <el-radio :label="3">不通过</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="原因" prop="content" v-if="dataForm.isPass==3">

        <el-input type="textarea" rows="6" v-model="dataForm.content" placeholder="不通过的原因"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus";
const emit = defineEmits(["refreshDataList"]);
import { dxget } from "@/utils/utils";
const xczxtrt = ref([])
const visible = ref(false);
const dataFormRef = ref();

const dataForm = reactive({
  id: '', userId: '', inviteUserPhone: '', inviteUserName: '', inviteUserId: '', inviteTime: '', balance: '', isRegist: '', sort: '', createTime: '', updateTime: ''
});

const rules = ref({
  userId: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  inviteUserPhone: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  inviteUserName: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  inviteUserId: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  inviteTime: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  balance: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  isRegist: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  sort: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  createTime: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  updateTime: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ]
});

const init = (id?: number) => {
  visible.value = true;
  dataForm.id = "";
  dataForm.isPass = "1"
  dataForm.content = ""
  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (id) {
    getInfo(id);
  }
};

// 获取信息
const getInfo = (id: number) => {
  baseService.get("/api/userinvite/" + id).then((res) => {
    Object.assign(dataForm, res.data);
  });
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    if (!valid) {
      return false;
    }
    (!dataForm.id ? baseService.post : baseService.put)("/api/userinvite", dataForm).then((res) => {
      ElMessage.success({
        message: '成功',
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

defineExpose({
  init
});
const jmkxcf = async () => {

  const { list } = await dxget('/api/user/page', {
    limit: 999
  })
  xczxtrt.value = list
}
jmkxcf()
</script>
